package com.braveman.im.ui.activity.message;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.braveman.im.R;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

public class SelectCreateGroupStatesActivity extends BaseActivity {

    private CheckBox mRdActivitySelectCompany;
    private CheckBox mRdActivitySelectPerson;
    private CheckBox mRdActivitySelectCompanyGroupForPlat;
    private TextView mBtnActivityNext;
    private int type = 1;
    private boolean palatformCheck;
    private boolean personCheck = true;
    private boolean companyCheck;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("新建群").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtils.finishActivity(SelectCreateGroupStatesActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_select_create_group_states;
    }

    @Override
    protected void initChildView() {
        mRdActivitySelectCompany = findViewById(R.id.rd_activity_select_company);
        mRdActivitySelectPerson = findViewById(R.id.rd_activity_select_person);
        mRdActivitySelectCompanyGroupForPlat =findViewById(R.id.rd_activity_select_company_group_for_plat);
        mBtnActivityNext = findViewById(R.id.btn_activity_next);

    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        mRdActivitySelectCompany.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                companyCheck = b;
                if (b) {
                    mRdActivitySelectPerson.setChecked(false);
                    mRdActivitySelectCompanyGroupForPlat.setChecked(false);
                }
            }
        });
        mRdActivitySelectPerson.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                personCheck = b;
                if (b) {
                    mRdActivitySelectCompany.setChecked(false);
                    mRdActivitySelectCompanyGroupForPlat.setChecked(false);
                }

            }
        });
        mRdActivitySelectCompanyGroupForPlat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                palatformCheck = b;
                if (b) {
                    mRdActivitySelectPerson.setChecked(false);
                    mRdActivitySelectCompany.setChecked(false);
                }
            }
        });
        mBtnActivityNext.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_activity_next:
                if (!companyCheck && !personCheck && !palatformCheck) {
                    UIUtils.showToast("请选择新建群类型");
                    return;
                } else {

                    if (companyCheck) {
                        ActivityUtils.startActivityAndFinish(SelectCreateGroupStatesActivity.this, CreateGroupActivity.class);
                    } else if (personCheck || palatformCheck) {
                        Bundle bundle = new Bundle();
                        bundle.putInt("type", type);
                        ActivityUtils.startActivityAndFinish(SelectCreateGroupStatesActivity.this, CreateGroupOnlyActivity.class, bundle);
                        break;

                    }
                    break;
                }
        }
    }
}